package org.extremengine.demo;

import java.awt.Graphics;

import org.extremengine.common.Point;
import org.extremengine.common.RigidBody;
import org.extremengine.common.Velocity;
import org.extremengine.shape.Circle;
import org.extremengine.shape.ParallelRectangle;

/**
 * 自由落体运动演示
 * 
 * @author yuxing
 * 
 */
public class PanelFalling extends BasePanelWorld {
	RigidBody ball;
	RigidBody box;
	RigidBody ball2;
	RigidBody ball3;

	public PanelFalling(DemoCallback demoCallback) {
		super(demoCallback);
	}

	@Override
	public void initDemoWorld() {
		super.initDemoWorld();

		// 初始化刚体
		ball = world.createRigidBody(new Object(), 0, 0.5, 0, new Circle(new Point(10.0, 28.0), 1.0));
		ball.setMass(30);// 30KG
		ball.setElasticity(0.9);

		box = world.createRigidBody(new Object(), 0, 0.2, 40, new ParallelRectangle(15, 20, 27, 32));

		ball2 = world.createRigidBody(new Object(), 0, 0.5, 10, new Circle(new Point(30, 2), 2));
		ball2.setV(new Velocity(20, 90));

		ball3 = world.createRigidBody(new Object(), 0, 0.5, 10, new Circle(new Point(40, 2), 2));
		ball3.setV(new Velocity(30, 90));
	}


	@Override
	public void paint(Graphics g) {
		super.paint(g);
		if (!world.isRunning()) {
			System.out.println("paint rigid body");
			super.drawRigidBody(g, ball);
			super.drawRigidBody(g, box);
			super.drawRigidBody(g, ball2);
			super.drawRigidBody(g, ball3);
		}
	}

}
